package buffer;

import cn.jwtool.jwcache.buffer.data.Catch;
import cn.jwtool.jwcache.buffer.data.JwCatchTemplate;
import cn.jwtool.jwcache.buffer.listener.init.ListenerInit;
import cn.jwtool.jwcache.thread.Timer;
import cn.jwtool.jwcache.thread.TimerInit;



/**
 * @author : willian fu
 * @version : 1.0
 */
@Timer
public class Main {

    @Timer
    public void task1(){
        System.out.println("任务一执行");
    }

    @Timer(value = 5, type = true)
    public void task2(){
        System.out.println("任务2执行");
    }

    public static void main(String[] args) throws InterruptedException {
        JwCatchTemplate catchTemplate = JwCatchTemplate.getInstance();
        catchTemplate.setValue("willian", "你好", 1000*5L);
        catchTemplate.setValue("mike", "滚", 1000*20L);
        catchTemplate.setValue("baby", "嘿嘿", 1000*10L);
        ListenerInit listenerInit = new ListenerInit();
        while (catchTemplate.getSize() > 0){
            catchTemplate.getKeys().forEach(k->{
                System.out.println(k + " => " + catchTemplate.getForClass(k, String.class) + " 将在 " + catchTemplate.getExpired(k) + "ms 后过期");
            });
            System.out.println("----------------------");
            Thread.sleep(2000);
        }
        TimerInit timerInit = new TimerInit();
    }
}
